<?php

namespace App\Http\Controllers\Admin\Meeting;


use App\Http\Controllers\Admin\BaseController;
use App\Models\MeetingGuest;
use Illuminate\Http\Request;

class GuestController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function get(Request $request)
    {
        return ajaxReturn(['guest' => MeetingGuest::find($request->input('id'))]);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function batchget(Request $request)
    {
        $query = MeetingGuest::query()->with(['group','hotel']);
        return ajaxReturn([
            'total' => $query->count(),
            'items' => $query->offset($request->input('offset', 0))
                ->limit($request->input('count', 15))
                ->get()
        ]);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function save(Request $request)
    {
        $guest = MeetingGuest::findOrNew($request->input('id'));
        $guest->fill($request->input('guest', []))->save();

        return ajaxReturn(['guest' => $guest]);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delete(Request $request)
    {
        MeetingGuest::whereKey($request->input('items', []))->delete();
        return ajaxReturn();
    }
}
